<?php

namespace Biz\model\GoodsTestActivity;

use Doraemon\pockets\datebase\BaseDbModel;
use Doraemon\tools\ImgUrl;
use Medoo\Medoo;

class FineGoodsWishMsgModel extends BaseDbModel
{

    public const _CONFIG_FILE_ = 'db_store';

    public const _CONFIG_SELECT_ = 'db_brand_activity';

    public const _DATABASE_ = 'brand_activity';

    public const _TABLE_NAME = 'fine_goods_test_wish_msg';

    public const STATUS_NORMAL = 1; //正常
    public const STATUS_DELETED = 9; //删除

    public const WISH_NORMAL = 1; //删除
    public const WISH_SPECIAL = 2; //删除




    /**
     * 获取一行
     * @param $where
     * @param string $field
     * @return array|mixed|null
     */
    public static function first($where, $field = '*')
    {
        $rs = self::get($field, $where);
        if (!$rs) {
            return null;
        }
        return $rs;
    }

    /**
     * 批量查询
     * @param $where
     * @param  $field
     * @return array|bool
     */
    public static function all($where, $field = '*')
    {
        return self::select($field, $where);
    }

    /**
     * 获取一列的值
     * @param $where
     * @param array $field
     * @return array|bool
     */
    public static function pluck($where, array $field = ['id'])
    {
        return self::select($field, $where);
    }

    /**
     * 从记录中获取单个值
     * @param $where
     * @param string $columns
     * @return array|bool
     */
    public static function value($where, string $columns = 'id')
    {
        return self::get($columns, $where);
    }

    /**
     * 获取所有许愿词列表
     * @param string $brand_name
     * @return array|bool
     */
    public static function getWishMsg($brand_name = '')
    {
        $list = self::all(['id[>]' => 0]);
        foreach ($list as &$item) {
            if ($brand_name) {
                $item['content'] = str_replace("BRAND", $brand_name, $item['content']);
            }
        }

        return $list;
    }

}